package amartin47;

import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.Socket;
import java.util.Date;

class Connect extends Thread {
   private Socket client = null;
   private ObjectInputStream ois = null;
   private ObjectOutputStream oos = null;
   private String currentLyrics;
   
    
   public Connect() {}

   public Connect(Socket clientSocket, String currentLyrics) {
     client = clientSocket;
     try {
      ois = new ObjectInputStream(client.getInputStream());
      oos = new ObjectOutputStream(client.getOutputStream());
      this.currentLyrics = currentLyrics;
     } catch(Exception e1) {
         try {
            client.close();
         }catch(Exception e) {
           System.out.println(e.getMessage());
         }
         return;
     }
     this.start();
   }

  
   public void run() {
      try {
         oos.writeObject(currentLyrics);
         oos.flush();
         // close streams and connections
         ois.close();
         oos.close();
         client.close(); 
      } catch(Exception e) {}       
   }
}